#include "fig_enemy_dragon.h"
#include "fig_bullet.h"
#include "fig_enemybullet_master.h"
#include "fig_sfx_manager.h"

#include "math/facing.h"
#include "num/rand.h"



FIGEnemyDragon::DragonPiece::DragonPiece() :	m_Rotation(0),
												m_Delay(0),
												m_ScaleX(1.0f)
{

}

void		FIGEnemyDragon::DragonPiece::Tick(float dt,
											  float MoveSpeed,
											  FIGFlyingPath::PATH_TYPE PType
											  )
{
	
	if( m_Delay > 0)
	{
		m_Delay -= dt;
		return;
	}

	const FIGFlyingPath::PathInfo PathInfo = FIGFlyingPath::Instance().GetPosFromPath
													(
													PType,
													m_PathCraftInfo,													
													dt
													);
												
	if(PathInfo.m_IsDone == false)
	{
		m_Rotation = m_Rotation + ( PathInfo.Rotation);
        if(m_Rotation > 360.0f)
            m_Rotation -= 360.0f;
        
        if(m_Rotation < 0.0f)
            m_Rotation += 360.0f;
        
		
		//if(m_CraftInfo.RotationDone < 0)
		//	m_CraftInfo.RotationDone *= -1;
		
		math::Vec2 Dir = math::Facing::VectorFromAngle(m_Rotation-180.0f);
		Dir.Normalize();
		float Dist = dt * MoveSpeed;
		m_Pos += ( Dir * Dist);
		m_PathCraftInfo.DistantTravelled += Dist;
		
	}
	
}

void		FIGEnemyDragon::DragonPiece::Render(const math::Vec2& Offset,
												float Scale,
												ui::UISprite& SpriteToRender												
												)
{
	SpriteToRender.m_Pos = m_Pos + Offset;
	SpriteToRender.m_Rotation = m_Rotation;
	SpriteToRender.m_Size =   SpriteToRender.m_SizeOriginal * Scale;
	SpriteToRender.m_Size.x *= m_ScaleX;
	SpriteToRender.RenderRotated();
}

